import 'package:flutter/material.dart';
import 'package:my_test_demo/page/main/index_page.dart';

import '../constant/router_constant.dart';
import '../page/login_page.dart';
import '../page/splash_page.dart';

//配置路由
final routes = {
  RouterConstant.SPLASH: (context) => SplashPage(),
  RouterConstant.LOGIN: (context) => LoginPage(),
  RouterConstant.INDEX: (context) => IndexPage(),
};

//固定写法
var onGenerateRoute = (RouteSettings settings) {
  // 统一处理
  final String? name = settings.name;
  final Function? pageContentBuilder = routes[name];
  if (pageContentBuilder != null) {
    if (settings.arguments != null) {
      final Route route = MaterialPageRoute(
        builder:
            (context) =>
                pageContentBuilder(context, arguments: settings.arguments),
      );
      return route;
    } else {
      final Route route = MaterialPageRoute(
        builder: (context) => pageContentBuilder(context),
      );
      return route;
    }
  }
};
